home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / PWORD_MC.ZIP / PASSWORD.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-04  |  2.4 KB  |  103 lines

  1. /**********************************************
  2. A Simple password program written using
  3. Borland's Turbo C++ for DOS v3.0.
  4. Written by:  Michael J. Campbell, 1994
  5.  
  6. Note:  Still not using all the new techniques
  7.          and classes yet.  I still seem to be
  8.          stuck doing C stuff, especially in I/O.
  9. **********************************************/
  10.  
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <graphics.h>
  15. #include <dos.h>
  16. #include <conio.h>
  17.  
  18. //Initialize functions
  19. extern void set_graph(void);
  20. extern void set_up(void);
  21. extern void wait(void);
  22. extern void change(void);
  23. extern int ESC_pressed;
  24. extern void write_text(int,int,int,int,int,int,int);
  25.  
  26. char text[30];  //Global temporary text variable
  27. char password[30];
  28.  
  29. void main(void)
  30.     {
  31.     int tries=0;
  32.     FILE *fp;
  33.  
  34.     // Disable control-break keypress
  35.     setcbrk(0);
  36.  
  37.     // Change to graphics mode
  38.     set_graph();
  39.  
  40.     // The old style for doing files
  41.     if((fp = fopen("c:\\allow.use","r")) == NULL)
  42.         {
  43.         fp = fopen("c:\\allow.use","w+");
  44.         fprintf(fp,"DEFAULT\0");
  45.         fclose(fp);
  46.         setcolor(WHITE);
  47.         settextjustify(LEFT_TEXT,CENTER_TEXT);
  48.         outtextxy(120,200,"INITIAL PASSWORD IS 'DEFAULT', YOU SHOULD CHANGE THIS.");
  49.         outtextxy(120,220,"THE PASSWORD IS CASE-SENSITIVE.  IT CAN INCLUDE SPACES");
  50.         outtextxy(120,240,"AND ALL ASCII CHARACTERS.");
  51.         outtextxy(120,260,"THE PASSWORD WILL BE KEPT IN YOUR ROOT DIRECTORY IN THE");
  52.         outtextxy(120,280,"FILE 'ALLOW.USE'.  IF YOU DELETE THIS FILE, THIS SCREEN");
  53.         outtextxy(120,300,"WILL BE DISPLAYED AGAIN.  YOU CAN ALSO MAKE IT A HIDDEN");
  54.         outtextxy(120,320,"FILE FOR FURTHER PROTECTION.     PRESS ANY KEY TO CONTINUE...");
  55.         settextjustify(CENTER_TEXT,CENTER_TEXT);
  56.  
  57.         getch();
  58.         cleardevice();
  59.         }
  60.  
  61.     // Get password
  62.     fp = fopen("c:\\allow.use","r");
  63.     fscanf(fp,"%s",&password);
  64.     fclose(fp);
  65.  
  66.     // Prompt user for password loop
  67.     while(1)
  68.         {
  69.         // Draw input box
  70.         set_up();
  71.         // Increment user tries
  72.         tries++;
  73.  
  74.         write_text(267,242,BLACK,BLACK,LIGHTGRAY,15,0);
  75.  
  76.         // If password matches, exit
  77.         if(strcmp(text,password) == 0) { restorecrtmode(); break; }
  78.  
  79.         // If user wants to change password
  80.         if(strcmp(text,"CHANGE") == 0)
  81.             {
  82.             ESC_pressed = 0;
  83.             change();
  84.  
  85.             // Get new password
  86.             fp = fopen("c:\\allow.use","r");
  87.             fscanf(fp,"%s",&password);
  88.             fclose(fp);
  89.             tries--;
  90.             }
  91.  
  92.         // Slap user on hand for not knowing password
  93.         if(tries > 2)
  94.             {
  95.             wait();
  96.             tries = 0;
  97.             }
  98.         }
  99.  
  100.     exit(1);
  101.     }
  102.  
  103.